<?php 
	defined('_JEXEC') or die('Restricted access');	
	include(JPATH_COMPONENT_ADMINISTRATOR.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'zipcodekey.php');
	include(JPATH_COMPONENT_ADMINISTRATOR.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'zipcode.php');

?>

<script>
	var zipcode_data = <?php echo $zipcode_json ?>;
	
	jQuery(document).ready(function(){
		jQuery('#zipcode').typeahead({
		  	source: <?php echo $zipcode_key ?>,
		  	onselect: function(value) { 
				var city = zipcode_data[value].City;
				var states = zipcode_data[value].Code;
				
				jQuery("#city").val(city);
				jQuery("#states").val(states);
			}
		})
	})
</script>
<form action="index.php" method="post" >
<div class="checkout_register row-fluid">		
	<div id="sj_login_box" class="show-box">	
		<div class="row-fluid">
			<div class="span6">
				<div class="sj_box_inner">
					<div class="sj_box_title">
						<h3>Billing Address</h3>
					</div>			
				</div>
					
					<div class="control-group">
                    	<label class="control-label" for="customer_name">
                        	<strong>Your name</strong><em>*</em>
						</label>
	                    <div class="controls row-fluid">
	                    	<input value="<?php echo $this->user->customer_name ?>" name="customer_name" id="customer_name" class="required" type="text">        
	                    </div>
                    </div>
                    
                    <div class="control-group">
                    	<label class="control-label" for="address">
                        	<strong>Address</strong><em>*</em>
						</label>
	                    <div class="controls row-fluid">
	                    	<input value="<?php echo $this->user->address ?>" name="address" id="address" class="required" type="text">
	                    </div>
                    </div>
                    
                    <div class="control-group">
                    	<label class="control-label" for="zipcode">
                        	<strong>Zipcode</strong><em>*</em>
						</label>
	                    <div class="controls row-fluid">
	                    	<input value="<?php echo $this->user->zipcode ?>" name="zipcode" id="zipcode" class="required" type="text">
	                    </div>
                    </div>
                    
                    <div class="control-group">
                    	<label class="control-label" for="city">
                        	<strong>City</strong>
						</label>
	                    <div class="controls row-fluid">
	                    	<input value="<?php echo $this->user->city ?>" name="city" id="city" type="text">
	                    </div>
                    </div>
                    
                    <div class="control-group">
                    	<label class="control-label" for="states">
                        	<strong>States</strong>
						</label>
	                    <div class="controls row-fluid">
	                    	<input value="<?php echo $this->user->states ?>" name="states" id="states" type="text">
	                    </div>
                    </div>
                    
                    <div class="control-group">
                    	<label class="control-label" for="mobile">
                        	<strong>Mobile phone</strong><em>*</em>
						</label>
	                    <div class="controls row-fluid">
	                    	<input value="<?php echo $this->user->mobile ?>" name="mobile" id="mobile" type="text">
	                    </div>
                    </div>					
				
			</div> 
			
			<div class="span6">
				<div class="sj_box_inner">
					<div class="sj_box_title">
						<h3>Order Summary</h3>
					</div>			
				</div>
				<div>
					<table id='table_cart' class="table table-striped table-bordered">
						<thead>
							<tr>
								<th><?php echo JText::_("COM_BAKERYS_CART_PRODUCTNAME") ?></th>
								<th><?php echo JText::_("COM_BAKERYS_CART_PRODUCTAMOUNT") ?></th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($this->cart as $item): ?>
								<tr>
									<td>
										<div class="PricesalesPrice" style="display:block !important">
											<span class="PricesalesPrice">
												<?php echo $item["productname"] ?>
											</span>
											x <?php echo $item["quantity"] ?>
											<br>
											Price:
											<span class="PricesalesPrice">
												 $<?php echo number_format($item["price"],2,".",",") ?>
											</span>
										</div>
									</td>
									
									<?php 
										$amount = $item["price"] * $item["quantity"]; 
										$subtotal += $amount;
									?>
									<td>
										<div class="text-right PricesalesPrice" style="display:block !important">
											<span class="PricesalesPrice product_amount">
												$<?php echo number_format($amount,2,".",",") ?>
											</span>
										</div>
										<input type='hidden' value='<?php echo $amount ?>' class='amount_hidden' />
									</td>
								</tr>
							<?php endforeach; ?>
						</tbody>
						<tfoot>
							<tr>
								<td colspan="2">
									<div class="text-right PricesalesPrice" style="display:block !important">
										<?php echo JText::_("COM_BAKERYS_CART_TOTAL") ?>
										<span class="PricesalesPrice" id="total_cart_hidden">
											$<?php echo number_format($subtotal,2,".",",") ?>
										</span>
									</div>
									
								</td>		
							</tr>				
						</tfoot>			
					</table>
				</div>
			</div>	
		</div>
	</div>
</div>	

<input type="submit" class="btn btn-primary" value="Create Order">
<input type="hidden" name="location_id" value="<?php echo JRequest::getVar("location") ?>">
<input type="hidden" name="location_alias" value="<?php echo JRequest::getVar("location_alias") ?>">		
<input type="hidden" name="option" value="com_bakerys">
<input type="hidden" name="task" value="billaddress.createorder">
</form>

<script src='<?php echo JUri::root(true)."/media/com_bakerys/js/bootstrap-typeahead.js" ?>' type='text/javascript'></script>
	